package com.leetcode.Offer;

import java.util.ArrayList;
import java.util.HashMap;

public class JZ57 {
    public int[] twoSum(int[] nums, int target) {

        if (nums.length == 1) {
            return new int[]{};
        }
        //动态规划
        //HashMap
        int[] ints = new int[2];
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(nums[i])) {
                ints[0] = nums[i];
                ints[1] = nums[map.get(nums[i])];
            } else {
                map.put(target - nums[i], i);
            }

        }
        return ints;

    }

}
